package com.j256.ormlite.stmt;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.logger.Logger;
import com.j256.ormlite.logger.LoggerFactory;
import com.j256.ormlite.stmt.mapped.MappedPreparedStmt;
import com.j256.ormlite.table.TableInfo;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public abstract class StatementBuilder<T, ID>
{
  private static Logger logger = LoggerFactory.getLogger(StatementBuilder.class);
  protected boolean addTableName;
  protected final Dao<T, ID> dao;
  protected final DatabaseType databaseType;
  protected final TableInfo<T, ID> tableInfo;
  protected final String tableName;
  protected StatementType type;
  protected Where<T, ID> where = null;

  public StatementBuilder(DatabaseType paramDatabaseType, TableInfo<T, ID> paramTableInfo, Dao<T, ID> paramDao, StatementType paramStatementType)
  {
    this.databaseType = paramDatabaseType;
    this.tableInfo = paramTableInfo;
    this.tableName = paramTableInfo.getTableName();
    this.dao = paramDao;
    this.type = paramStatementType;
    if (!paramStatementType.isOkForStatementBuilder())
      throw new IllegalStateException("Building a statement from a " + paramStatementType + " statement is not allowed");
  }

  protected abstract void appendStatementEnd(StringBuilder paramStringBuilder, List<ArgumentHolder> paramList)
    throws SQLException;

  protected abstract void appendStatementStart(StringBuilder paramStringBuilder, List<ArgumentHolder> paramList)
    throws SQLException;

  protected void appendStatementString(StringBuilder paramStringBuilder, List<ArgumentHolder> paramList)
    throws SQLException
  {
    appendStatementStart(paramStringBuilder, paramList);
    appendWhereStatement(paramStringBuilder, paramList, WhereOperation.FIRST);
    appendStatementEnd(paramStringBuilder, paramList);
  }

  protected boolean appendWhereStatement(StringBuilder paramStringBuilder, List<ArgumentHolder> paramList, WhereOperation paramWhereOperation)
    throws SQLException
  {
    if (this.where == null)
    {
      WhereOperation localWhereOperation = WhereOperation.FIRST;
      boolean bool = false;
      if (paramWhereOperation == localWhereOperation)
        bool = true;
      return bool;
    }
    paramWhereOperation.appendBefore(paramStringBuilder);
    Where localWhere = this.where;
    if (this.addTableName);
    for (String str = this.tableName; ; str = null)
    {
      localWhere.appendSql(str, paramStringBuilder, paramList);
      paramWhereOperation.appendAfter(paramStringBuilder);
      return false;
    }
  }

  protected String buildStatementString(List<ArgumentHolder> paramList)
    throws SQLException
  {
    StringBuilder localStringBuilder = new StringBuilder(128);
    appendStatementString(localStringBuilder, paramList);
    String str = localStringBuilder.toString();
    logger.debug("built statement {}", str);
    return str;
  }

  @Deprecated
  public void clear()
  {
    reset();
  }

  protected FieldType[] getResultFieldTypes()
  {
    return null;
  }

  StatementType getType()
  {
    return this.type;
  }

  protected MappedPreparedStmt<T, ID> prepareStatement(Long paramLong)
    throws SQLException
  {
    ArrayList localArrayList = new ArrayList();
    String str = buildStatementString(localArrayList);
    ArgumentHolder[] arrayOfArgumentHolder = (ArgumentHolder[])localArrayList.toArray(new ArgumentHolder[localArrayList.size()]);
    FieldType[] arrayOfFieldType1 = getResultFieldTypes();
    FieldType[] arrayOfFieldType2 = new FieldType[localArrayList.size()];
    for (int i = 0; i < arrayOfArgumentHolder.length; i++)
      arrayOfFieldType2[i] = arrayOfArgumentHolder[i].getFieldType();
    if (!this.type.isOkForStatementBuilder())
      throw new IllegalStateException("Building a statement from a " + this.type + " statement is not allowed");
    TableInfo localTableInfo = this.tableInfo;
    if (this.databaseType.isLimitSqlSupported());
    for (Long localLong = null; ; localLong = paramLong)
      return new MappedPreparedStmt(localTableInfo, str, arrayOfFieldType2, arrayOfFieldType1, arrayOfArgumentHolder, localLong, this.type);
  }

  public StatementInfo prepareStatementInfo()
    throws SQLException
  {
    ArrayList localArrayList = new ArrayList();
    return new StatementInfo(buildStatementString(localArrayList), localArrayList, null);
  }

  public String prepareStatementString()
    throws SQLException
  {
    return buildStatementString(new ArrayList());
  }

  public void reset()
  {
    this.where = null;
  }

  public void setWhere(Where<T, ID> paramWhere)
  {
    this.where = paramWhere;
  }

  protected boolean shouldPrependTableNameToColumns()
  {
    return false;
  }

  protected FieldType verifyColumnName(String paramString)
  {
    return this.tableInfo.getFieldTypeByColumnName(paramString);
  }

  public Where<T, ID> where()
  {
    this.where = new Where(this.tableInfo, this, this.databaseType);
    return this.where;
  }

  public static class StatementInfo
  {
    private final List<ArgumentHolder> argList;
    private final String statement;

    private StatementInfo(String paramString, List<ArgumentHolder> paramList)
    {
      this.argList = paramList;
      this.statement = paramString;
    }

    public List<ArgumentHolder> getArgList()
    {
      return this.argList;
    }

    public String getStatement()
    {
      return this.statement;
    }
  }

  public static enum StatementType
  {
    private final boolean okForExecute;
    private final boolean okForQuery;
    private final boolean okForStatementBuilder;
    private final boolean okForUpdate;

    static
    {
      DELETE = new StatementType("DELETE", 4, true, false, true, false);
      EXECUTE = new StatementType("EXECUTE", 5, false, false, false, true);
      StatementType[] arrayOfStatementType = new StatementType[6];
      arrayOfStatementType[0] = SELECT;
      arrayOfStatementType[1] = SELECT_LONG;
      arrayOfStatementType[2] = SELECT_RAW;
      arrayOfStatementType[3] = UPDATE;
      arrayOfStatementType[4] = DELETE;
      arrayOfStatementType[5] = EXECUTE;
    }

    private StatementType(boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, boolean paramBoolean4)
    {
      this.okForStatementBuilder = paramBoolean1;
      this.okForQuery = paramBoolean2;
      this.okForUpdate = paramBoolean3;
      this.okForExecute = paramBoolean4;
    }

    public boolean isOkForExecute()
    {
      return this.okForExecute;
    }

    public boolean isOkForQuery()
    {
      return this.okForQuery;
    }

    public boolean isOkForStatementBuilder()
    {
      return this.okForStatementBuilder;
    }

    public boolean isOkForUpdate()
    {
      return this.okForUpdate;
    }
  }

  protected static enum WhereOperation
  {
    private final String after;
    private final String before;

    static
    {
      AND = new WhereOperation("AND", 1, "AND (", ") ");
      OR = new WhereOperation("OR", 2, "OR (", ") ");
      WhereOperation[] arrayOfWhereOperation = new WhereOperation[3];
      arrayOfWhereOperation[0] = FIRST;
      arrayOfWhereOperation[1] = AND;
      arrayOfWhereOperation[2] = OR;
    }

    private WhereOperation(String paramString1, String paramString2)
    {
      this.before = paramString1;
      this.after = paramString2;
    }

    public void appendAfter(StringBuilder paramStringBuilder)
    {
      if (this.after != null)
        paramStringBuilder.append(this.after);
    }

    public void appendBefore(StringBuilder paramStringBuilder)
    {
      if (this.before != null)
        paramStringBuilder.append(this.before);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.j256.ormlite.stmt.StatementBuilder
 * JD-Core Version:    0.6.2
 */